﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class CityMgr
{
    private static CityMgr _instance;
    public static CityMgr Instance
    {
        get {
            if (_instance == null) _instance = new CityMgr();
            return _instance;
        }
    }

    private List<City> _citys = new List<City>();
    public void AddCity(City city)
    {
        _citys.Add(city);
    }

    public City GetNearCity(Vector3 pos)
    {
        var minDistance = float.MaxValue;
        City nearCity = null;
        foreach (var city in _citys)
        {
            var distance = (city.transform.position - pos).sqrMagnitude;
            if(distance < minDistance)
            {
                nearCity = city;
                minDistance = distance;
            }
        }

        if(minDistance < 100)//temp code
        {
            return nearCity;
        }

        return null;
    }
}

